//
//  TTHomeCell.swift
//  NewWeiBo
//
//  Created by 吴天益 on 2017/7/26.
//  Copyright © 2017年 ttt. All rights reserved.
//

import UIKit
import SnapKit

class TTHomeCell: UITableViewCell {
    
    var buttonViewTopConstraint: Constraint?
    
    var weiBoViewModel: TTWeiBoViewModel?{
        didSet{
            
            originalView.weiBoViewModel = weiBoViewModel
//            ReweetView.weiBoViewModel = weiBoViewModel
            buttonView.weiBoViewModel = weiBoViewModel
            
            //卸载约束
            buttonViewTopConstraint?.deactivate()
            //假如没有转发微博数据,那么不需要显示转发微博视图
            if weiBoViewModel?.weiBoModel?.retweeted_status == nil {
                
                ReweetView.isHidden = true
                
                buttonView.snp.makeConstraints({ (make) in
                    
                   buttonViewTopConstraint = make.top.equalTo(originalView.snp.bottom).constraint
                })
            }else{
                ReweetView.isHidden = false
                
                buttonView.snp.makeConstraints({ (make) in
                    buttonViewTopConstraint = make.top.equalTo(ReweetView.snp.bottom).constraint
                })
//                print("1111")
//                print(weiBoViewModel?.weiBoModel?.pic_urls?.count ?? 0)
                //传递数据
                ReweetView.weiBoViewModel = weiBoViewModel
            }
        }
    }
    
    
    
    //原始微博
    lazy var originalView: HMHomeOriginalView = HMHomeOriginalView(frame: .zero)
    //转载微博
    lazy var ReweetView: HMHomeReweetView = HMHomeReweetView(frame: .zero)
    //底部按钮view
    lazy var buttonView: HMHomeToolBar = HMHomeToolBar()
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 界面设置
    func setupUI() {
        
        contentView.addSubview(originalView)
        contentView.addSubview(ReweetView)
        contentView.addSubview(buttonView)
        
        originalView.snp.makeConstraints { (make) in
            make.top.leading.trailing.equalTo(contentView)
//            make.height.equalTo(100)
        }
        ReweetView.snp.makeConstraints { (make) in
            make.top.equalTo(originalView.snp.bottom)
            make.leading.trailing.equalTo(contentView)
//            make.height.equalTo(50)
        }
        buttonView.snp.makeConstraints { (make) in
            buttonViewTopConstraint = make.top.equalTo(ReweetView.snp.bottom).constraint
//            make.height.equalTo(35)
            make.leading.bottom.trailing.equalTo(contentView)
        }
    }
}
